package com.grizz.snake.controller.factory;

import org.newdawn.slick.SlickException;
import org.newdawn.slick.tiled.TiledMap;

import com.grizz.snake.controller.InputController;
import com.grizz.snake.controller.Mediator;
import com.grizz.snake.controller.MovementService;
import com.grizz.snake.map.Map;
import com.grizz.snake.player.Snake;
import com.grizz.snake.resource.ResourceContainer;
import com.grizz.snake.target.Food;

public class EntityFactory {
	private Mediator mediator;
	private ResourceContainer resourceContainer;

	public EntityFactory(Mediator mediator) {
		this.mediator = mediator;
		mediator.register(this);
		resourceContainer = new ResourceContainer();
	}

	public InputController getInputController() {
		return new InputController(mediator);
	}

	public Map getMap() throws SlickException {
		TiledMap tiledMap = resourceContainer.getTiledMap("defaultBoard");
		return new Map(tiledMap);
	}

	public MovementService getMovementService() {
		return new MovementService(mediator);
	}

	public Snake getSnake() throws SlickException {
		Snake snake = new Snake(15, 20, mediator);
		
		snake.setHeadImage(resourceContainer.getImage("headD"), Snake.GO_DOWN);
		snake.setHeadImage(resourceContainer.getImage("headU"), Snake.GO_UP);
		snake.setHeadImage(resourceContainer.getImage("headL"), Snake.GO_LEFT);
		snake.setHeadImage(resourceContainer.getImage("headR"), Snake.GO_RIGHT);
		
		snake.setTailImage(resourceContainer.getImage("tailD"), Snake.GO_DOWN);
		snake.setTailImage(resourceContainer.getImage("tailU"), Snake.GO_UP);
		snake.setTailImage(resourceContainer.getImage("tailL"), Snake.GO_LEFT);
		snake.setTailImage(resourceContainer.getImage("tailR"), Snake.GO_RIGHT);
		
		snake.setBodyImage(resourceContainer.getImage("body"));
		return snake;
	}
	
	public Food getFood() throws SlickException{
		Food food = new Food(mediator);
		
		food.setFoodImage(resourceContainer.getImage("food"));
		
		return food;
	}

}
